﻿using System.Xml.Serialization;

namespace Tools
{
    public class Serializable
    {
        public static string Serialize(object objEntity)
        {
            string strRetVal = "";
            using (System.IO.StringWriter oWriter = new System.IO.StringWriter())
            {
                XmlSerializer oSerializer = new XmlSerializer(objEntity.GetType());
                oSerializer.Serialize(oWriter, objEntity);
                strRetVal = oWriter.ToString();
            }
            return strRetVal;
        }
        public static object Deserialize(System.Type objType, string strEntity)
        {
            object objRetVal = null;
            using (System.IO.StringReader oReader = new System.IO.StringReader(strEntity))
            {
                XmlSerializer oSerializer = new XmlSerializer(objType);
                objRetVal = oSerializer.Deserialize(oReader);
            }
            return objRetVal;
        }
        
    }
}
